home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbsrc.zip / RAY.C < prev    next >
C/C++ Source or Header  |  1991-05-04  |  4KB  |  126 lines

  1. /*****************************************************************************
  2. *
  3. *                                      ray.c
  4. *
  5. *   from DKBTrace (c) 1990  David Buck
  6. *
  7. *  This module implements functions pertaining to rays.
  8. *
  9. * This software is freely distributable. The source and/or object code may be
  10. * copied or uploaded to communications services so long as this notice remains
  11. * at the top of each file.  If any changes are made to the program, you must
  12. * clearly indicate in the documentation and in the programs startup message
  13. * who it was who made the changes. The documentation should also describe what
  14. * those changes were. This software may not be included in whole or in
  15. * part into any commercial package without the express written consent of the
  16. * author.  It may, however, be included in other public domain or freely
  17. * distributed software so long as the proper credit for the software is given.
  18. *
  19. * This software is provided as is without any guarantees or warranty. Although
  20. * the author has attempted to find and correct any bugs in the software, he
  21. * is not responsible for any damage caused by the use of the software.  The
  22. * author is under no obligation to provide service, corrections, or upgrades
  23. * to this package.
  24. *
  25. * Despite all the legal stuff above, if you do find bugs, I would like to hear
  26. * about them.  Also, if you have any comments or questions, you may contact me
  27. * at the following address:
  28. *
  29. *     David Buck
  30. *     22C Sonnet Cres.
  31. *     Nepean Ontario
  32. *     Canada, K2H 8W7
  33. *
  34. *  I can also be reached on the following bulleton boards:
  35. *
  36. *     OMX              (613) 731-3419
  37. *     Mystic           (613) 596-4249  or  (613) 596-4772
  38. *
  39. *  Fidonet:   1:163/109.9
  40. *  Internet:  dbuck@ccs.carleton.ca
  41. *  The "You Can Call Me RAY" BBS    (708) 358-5611
  42. *
  43. *  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  44. *
  45. *     The "You Can Call Me RAY" BBS (708) 358-5611
  46. *     The Information Exchange BBS  (708) 945-5575
  47. *
  48. *****************************************************************************/
  49.  
  50.  
  51.  
  52. #include "frame.h"
  53. #include "vector.h"
  54. #include "dkbproto.h"
  55.  
  56. #define Mix(a,b,c) { \
  57.    (a).x = (b).x * (c).y; \
  58.    (a).y = (b).x * (c).z; \
  59.    (a).z = (b).y * (c).z; }
  60.  
  61. void Make_Ray(r)
  62.    RAY *r;
  63.    {
  64.    VECTOR Temp_Init_Dir;
  65.  
  66.    VSquareTerms (r -> Initial_2, r -> Initial);
  67.    VSquareTerms (r -> Direction_2, r -> Direction);
  68.    VEvaluate (r -> Initial_Direction, r -> Initial, r -> Direction);
  69.    Mix (r -> Mixed_Initial_Initial, r -> Initial, r -> Initial);
  70.    Mix (r -> Mixed_Dir_Dir, r -> Direction, r -> Direction);
  71.    Mix (Temp_Init_Dir, r -> Initial, r -> Direction);
  72.    Mix (r -> Mixed_Init_Dir, r -> Direction, r -> Initial);
  73.    VAdd (r -> Mixed_Init_Dir, r -> Mixed_Init_Dir, Temp_Init_Dir);
  74.    r -> Quadric_Constants_Cached = TRUE;
  75.    }
  76.  
  77. void Initialize_Ray_Containers (Ray)
  78.    RAY *Ray;
  79.    {
  80.    Ray -> Containing_Index = -1;
  81.    }
  82.  
  83. void Copy_Ray_Containers (Dest_Ray, Source_Ray)
  84.    RAY *Dest_Ray, *Source_Ray;
  85.    {
  86.    register int i;
  87.    
  88.    if ((Dest_Ray -> Containing_Index = Source_Ray -> Containing_Index)
  89.          >= MAX_CONTAINING_OBJECTS) {
  90.       fprintf (stderr, "ERROR - Containing Index too high\n");
  91.       close_all();
  92.       exit (1);
  93.       }
  94.  
  95.    for (i = 0 ; i < MAX_CONTAINING_OBJECTS ; i++) {
  96.       Dest_Ray -> Containing_Textures[i] = Source_Ray -> Containing_Textures[i];
  97.       Dest_Ray -> Containing_IORs[i] = Source_Ray -> Containing_IORs[i];
  98.       }
  99.    }
  100.  
  101. void Ray_Enter (ray, texture)
  102.    RAY *ray;
  103.    TEXTURE *texture;
  104.    {
  105.    register int index;
  106.  
  107.    if ((index = ++(ray -> Containing_Index)) >= MAX_CONTAINING_OBJECTS) {
  108.       fprintf (stderr, "Too many nested refracting objects\n");
  109.       close_all();
  110.       exit(1);
  111.       }
  112.  
  113.    ray -> Containing_Textures [index] = texture;
  114.    ray -> Containing_IORs [index] = texture->Object_Index_Of_Refraction;
  115.    }
  116.  
  117. void Ray_Exit (ray)
  118.    RAY *ray;
  119.    {
  120.    if (--(ray -> Containing_Index) < -1) {
  121.       fprintf (stderr, "Too many exits from refractions\n");
  122.       close_all();
  123.       exit(1);
  124.       }
  125.    }
  126.